{extend name="layout" /}
{block name="content"}
<style>
    .layui-tree-icon {
        height: 14px;
        line-height: 12px;
        width: 17px;
        text-align: center;
        border: 1px solid #c0c4cc;
    }
</style>

<div class="layui-tab layui-tab-brief">
	<ul class="layui-tab-title">
	    <li><a href="{:url('index')}">{$pathCurrent['name']}</a></li>
	    <li class="layui-this">{empty name="info"}添加{else /}编辑{/empty}核销账号</li>
  	</ul>
</div>
<div class="layui-card-body">
	<form class="layui-form" data-model="form-submit">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
		  	<legend>基本设置</legend>
		</fieldset>

		<div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="name" value="{$info['name']}" datatype="*">
            </div>
        </div>
		<div class="layui-form-item">
			<label class="layui-form-label">账号</label>
			<div class="layui-input-block">
				<input type="text" class="layui-input" name="phone" value="{$info['phone']}" datatype="*">
			</div>
		</div>
		<div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" class="layui-input" name="password" value="{$info['password_show']}">
            </div>
        </div>

		<div class="layui-form-item">
	    	<label class="layui-form-label">状态</label>
	    	<div class="layui-input-block">
	    		{php}$state = isset($info['status']) ? $info['status'] : '1';{/php}
	      		<input type="radio" name="status" value="1" title="启用" {if $state eq 1} checked="" {/if}>
	      		<input type="radio" name="status" value="2" title="冻结" {if $state eq 2} checked="" {/if}>
	    	</div>
	  	</div>
        


		<div class="layui-form-item">
	    	<div class="layui-input-block">
	    		<input type="hidden" name="id" value="{$info['id']}">
	      		<button class="layui-btn layui-btn-normal">保存</button>
	      		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	    	</div>
	  	</div>
	</form>
</div>
{/block}
{block name="js"}
<script type="text/javascript" src="/static/lib/assets/data.js"></script>
<script type="text/javascript">
    var mixin = {};
    var cs = 0;
    layui.use(['form'],function(){
        var form = layui.form;

       $.each($('#check_box .layui-unselect'),function(index){
            $(this).click(function(){
                if ( $('.powerCheckbox').eq(index).attr('pid') == 0 && cs == 0 ) {
                    var status = $('.powerCheckbox').eq(index).prop('checked')
                    checkboxStatus( $('.powerCheckbox').eq(index).val(), $('.powerCheckbox').eq(index).prop('checked'), index);
                }else if( $('.powerCheckbox').eq(index).attr('pid') != 0 && cs == 0 ){
                    checkboxSon($('.powerCheckbox').eq(index).attr('pid'))
                }
            });

        })

    });

    function checkboxStatus( val, status, ind ){
        cs = 1
        $.each($('#check_box .layui-unselect'),function(index){
            if ( $('.powerCheckbox').eq(index).attr('pid') == val ) {
                $(this).trigger("click");
            }
        })
        cs = 0
    }
    function checkboxSon( val ){
        cs = 1
        var num = 0
        var total = 0
        var ind = -1
        //$(this).trigger("click");
        $.each($('#check_box .layui-unselect'),function(index){
            if( $('.powerCheckbox').eq(index).val() == val ){
                ind = index
            }
            if ( $('.powerCheckbox').eq(index).attr('pid') == val ) {
                total++;
                if ( $('.powerCheckbox').eq(index).prop('checked') == true ) {
                    num++
                }
            }
        })

        if( total == num ){
            $('#check_box .layui-unselect').eq(ind).trigger("click");
        }else{
            if ( $('.powerCheckbox').eq(ind).prop('checked') == true ) {
                $('#check_box .layui-unselect').eq(ind).trigger("click");
            }
        }
        // cs = 0
    }


    
    

</script>
{/block}